#pragma once
#include "afxwin.h"
#include <gl/gl.h>
#include <gl/glu.h>
#include <vector>
#include <Definition.h>
#include <DSOpenGLDrawer.h>

//Reference:
//1.http://blog.sina.com.cn/s/blog_6ac675410100o0t6.html
//2.http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c10975__2/Setting-Up-OpenGL-in-an-MFC-Control.htm
//3.NeHe L13 - Draw text: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13
#define DEFAULT_BLOCK_COLOR RGB(132, 112, 255)	//gl = RGB(0.48f, 0.44f, 1.0f)		//Light Slate Blue
#define DEFAULT_BKGRD_COLOR	RGB(0, 0, 0)


class CDSGLDrawer :	public COpenGLDrawer
{
//================ Data member ==================
	private:
//Grid
		char m_szShowMouseCoordinate[256];
		char m_szPicRootDirPath[MAX_PATH];

		float m_fGridWidth;
		float m_fGridHeight;
		std::vector<CDSGrid> m_vcdsGrid;
		std::vector<CDSAStarCell> m_vcdsGrid4AStar;
		std::vector<CDSAStarCell> m_vcdsGrid4DrawBlocking;		//For Drawing block site

//============== Member Function =================
	public:
		CDSGLDrawer(void);
		~CDSGLDrawer(void);

//Specification
		void AddGrid(int x, int y, CDSGrid cdsGrid, BOOL IsWalkable = TRUE);
		void OnLButtonUp(UINT nFlags, CPoint point, int nDisplayMode, COLORREF clrPickItemColor, char* pcPicFilePath, 
						CDSAStarCell *pcdsRtnGrid = NULL);

		inline void SetGridBounadry(float fWidth, float fHeight) {
			m_fGridWidth = fWidth;
			m_fGridHeight = fHeight;
		};

		inline void SetPicRootDirPath(const char* szFilePath) { strcpy(m_szPicRootDirPath, szFilePath); };

//	For AStar
		void CleanScreen(void);
		void SetAStarCellInfo(unsigned int unIndex, CDSAStarCell cdsAStarCell);

	protected:
		virtual void glDrawScene(void);
		void OnObjectSelection(CPoint point, int nDisplayMode = DS_CELL_DISPLAY_MODE_COLOR, COLORREF clrPickColor = DEFAULT_BLOCK_COLOR, 
								char* pcPicFilePath = NULL, CDSAStarCell *pcdsRtnGrid = NULL );		//Default = Light Slate Blue
		void DrawTargets(void);

	public:
		DECLARE_MESSAGE_MAP()
//============ MFC ====================
	public:
		afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
		afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
		afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
		afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
};
